/*
 * Copyright (C) 2015 备胎金服
 * 未经授权允许不得进行拷贝和修改
 *   http://www.btjf.com/
 */
package com.zhangman.androidgame;

import com.zhangman.framework.Game;
import com.zhangman.framework.Graphics;
import com.zhangman.framework.Input;
import com.zhangman.framework.Screen;
import java.util.List;

/**
 * Created by zhangman on 2016/11/1 14:48.
 * Email: zhangman523@126.com
 */
public class MainMenuScreen extends Screen {

  public MainMenuScreen(Game game) {
    super(game);
  }

  @Override public void update(float deltaTime) {
    Graphics g = mGame.getGraphics();
    List<Input.TouchEvent> touchEvents = mGame.getInput().getTouchEvents();

    int len = touchEvents.size();
    for (int i = 0; i < len; i++) {
      Input.TouchEvent event = touchEvents.get(i);
      if (event.type == Input.TouchEvent.TOUCH_UP) {
        if (inBounds(event, 50, 350, 250, 450)) {
          mGame.setScreen(new GameScreen(mGame));
        }
      }
    }
  }

  private boolean inBounds(Input.TouchEvent event, int x, int y, int width, int height) {
    if (event.x > x && event.x < x + width - 1 && event.y > y && event.y < y + height - 1) {
      return true;
    } else {
      return false;
    }
  }

  @Override public void pain(float deltaTime) {
    Graphics g = mGame.getGraphics();
    g.drawImage(Assets.menu, 0, 0);
  }

  @Override public void pause() {

  }

  @Override public void resume() {

  }

  @Override public void dispose() {

  }

  @Override public void backButton() {
    //Display "Exit Game?" Box
    android.os.Process.killProcess(android.os.Process.myPid());
  }
}
